/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

/**
 * <p>Project: jse2303 - Ex3</p>
 * <p>Powered by webrx On 2023-07-27 11:37:10</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex3 {
    Object a = new Object();
    Object b = new Object();

    public static void main(String[] args) {
        var t = new Ex3();
        var ta = new Thread(t::a);
        var tb = new Thread(t::b);
        ta.start();
        tb.start();
    }

    void a() {
        synchronized (a) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {
                e.printStackTrace();
            }
            synchronized (b) {

            }
        }
    }

    void b() {
        synchronized (b) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {
                e.printStackTrace();
            }
            synchronized (a) {

            }
        }
    }
}
